package 动态链表.逢7过;


import 动态数组.线性表.ArrayList;
import 动态链表.LinkedSinglyCircularList;

import java.util.Scanner;

public class SaveGamePlus {
    //m为总的人数，startNum开始数字，endNum结束数字，startPlayer开始玩家编号，selfPlayer自己玩家的编号
    private static int m,startNum,endNum,startPlayer,selfPlayer;

    public static void main(String[] args) {
        input();
//        玩家1号的回答顺序为：10/10 [1,6,11,16,过,26,31,36,41,46]
        playGameAndOutPut();
    }

    private static void playGameAndOutPut() {
        LinkedSinglyCircularList<ArrayList<String>> list = new LinkedSinglyCircularList<>();
        for (int i = 0; i < m; i++) {
            //初始化玩家数组
            list.add(new ArrayList<String>());
        }

        //开始玩家的编号
        int index = startPlayer - 1;
        for (int i = startNum; i <= endNum; i++) {
            list.get(index++ % list.size()).add(getAnsWer(i));
        }

        System.out.println(String.format("玩家%d号的回答顺序为：%s",selfPlayer,list.get(selfPlayer - 1)));
    }

    private static void input() {
        System.out.println("***逢七过游戏***");
        Scanner input = new Scanner(System.in);
        System.out.print("输入总的玩家数量：");
        m = input.nextInt();
        System.out.print("输入开始的玩家编号(1-"+m+")：");
        startPlayer = input.nextInt();
        System.out.print("输入开始的数字：");
        startNum = input.nextInt();
        System.out.print("输入结束的数字：");
        endNum = input.nextInt();
        System.out.print("输入你的是几号玩家：");
        selfPlayer = input.nextInt();
    }

    private static String getAnsWer(int i) {
        if (i % 7 == 0){
            return "过";
        }
        if (containSeven(i)){
            return "过";
        }
        return i+"";
    }

    private static boolean containSeven(int i) {
        String num = i + "";
        return num.contains("7");
    }



}
